﻿import { Employee } from './../domain/model/employee';
import { EmployeeService } from './../service/employeeService';
import { KitchensolutionService } from './../service/kitchensolutionService';
import { CloudSyncService } from './../service/cloudSyncService';
import { DeviceService } from './../service/deviceService';
import { Response, ServiceConfig, route, Guid } from '../common';
import { Device } from '../domain/model';
import { WebException } from './webException';
import * as Koa from "koa";

export class EmployeeController {
    private employeeService: EmployeeService;
    private syncSvr: CloudSyncService;
    constructor() {
        this.employeeService = ServiceConfig.Current.GetService<EmployeeService>("employeeService");
    }

    toString(){
        return "EmployeeController";
    }

    @route({ method: 'get', path: '/api/employees/getWaiterList' })
    async getWaiterList(ctx, next) {
        let rst = await this.employeeService.getEmployeeByRole("waiter");
        ctx.response.body = Response.ok("获取列表成功", rst);
        await next();
    }

    @route({ method: 'get', path: '/api/employees/getBusserList' })
    async getBusserList(ctx, next) {
        let rst = await this.employeeService.getEmployeeByRole("busser");
        ctx.response.body = Response.ok("获取列表成功", rst);
        await next();
    }

    @route({ method: "get", path: "/api/employees" })
    async queryEmployees(ctx: Koa.Context, next) {
        const employees = await this.employeeService.findEmployees();
        employees.forEach(employe=>{
            employe.user&&(delete employe.user.pic)
        })
        ctx.response.body = Response.ok("success", employees);
        await next();
    }

    @route({ method: "put", path: "/api/employees/:id" })
    async updateEmployee(ctx: Koa.Context, next) {
        const body:Employee = ctx.request.body.employee;
        const employee = await this.employeeService.updateEmployee(body);
        ctx.response.body = Response.ok("success", {employee});
        await next();
    }
}